## 自定义的操作方法
actions () {
	RES_COL=60
    MOVE_TO_COL="echo -en \E[${RES_COL}G"

	case $1 in
		"echo_success")
			echo -n "$2" && $MOVE_TO_COL 
			echo  "[" `echo -en "\E[32;1m  OK \E[0m"` "]"
			;;
		"echo_tips")
			echo -n "$2" && $MOVE_TO_COL 
			echo  "[" `echo -en "\E[33;1m Tips \E[0m"` "]"
			;;
		"echo_error")
			echo -n "$2" && $MOVE_TO_COL 
			echo  "[" `echo -en "\E[31;1m Error \E[0m"` "]"
			exit
			;;
		"error_normal")
			echo -n "$2" && $MOVE_TO_COL 
			echo  "[" `echo -en "\E[0;1m Normal \E[0m"` "]"
			exit
			;;	
		*)
			echo "请定义方法"
			exit;
			;;
	esac			
}

## 去除字符串头尾的空白字符
trim (){
	str=""
    if [ $# -gt 0 ]; then
        str="$1"
    fi
    echo "$str" | sed -e 's/^[ \t\r\n]*//g' | sed -e 's/[ \t\r\n]*$//g'
}

## 获取操作系统的标识符
## rhel | centos | ubuntu 
os_type () {
    os=$(trim $(awk -F'[ "]' '/^NAME/{print $2}' /etc/os-release))

    if [ "$os" = "" ]; then
        os=$(trim $(lsb_release -i 2>/dev/null | awk -F: '{print $2}'))
    fi
    if [ ! "$os" = "" ]; then
        os=$(echo $os | tr '[A-Z]' '[a-z]')
    fi

    echo $os
}

## 获取操作系统的版本信息
os_version (){
	case `os_type` in
		"centos")
			echo `awk -F'"' '/^VERSION_ID/{print $2}' /etc/os-release`
			;;
		"ubuntu")
			echo `awk -F'"' '/^VERSION_ID/{print $2}' /etc/os-release`
			;;	
		*)
			echo 'unknow os_version'
			exit;
			;;
    esac	
}
